# $Id: Makefile 71 2012-07-20 16:11:45Z alan.watson.f $

all			:	all-liboaxaca			\
				all-libs 			\
				all-bins
install			:	install-liboaxaca		\
				install-bins			\
				install-libs
uninstall		:	uninstall-liboaxaca		\
				uninstall-bins			\
				uninstall-libs
doc			:	doc-libs
clean			:	clean-liboaxaca			\
				clean-libs
dist-clean		:	dist-clean-libs

COMPILED_LIBS 		= 	lib/oaxaca/foreign$(SO)
SCM_LIBS 		= 	lib/oaxaca/ao.sld 		\
				lib/oaxaca/log.sld		\
				lib/oaxaca/wfc.sld

XCPPFLAGS 		+=	-Iliboaxaca 			\
				-I$(PREFIX)/include/
XCFLAGS 		+=	-O -Wall
XLIBS 			+=	-Lliboaxaca/ 			\
				-loaxaca 			\
				-lmirrorDriver 			\
				-lmirrorDriverExtras 		\
				-lpthread			\
				-lrt				\
				-L$(PREFIX)/lib/

include Makefile.libs

################################################################################

BINS	=			bin/oaxaca			\
				bin/oaxaca-monitor		\
				bin/oaxaca-wfc			\
				bin/oaxaca-wfs

BIN_CXXFLAGS	=		-O -Wall -Iliboaxaca/
BIN_LIBS	=		-Lliboaxaca/ -loaxaca \
				-lmirrorDriver -lmirrorDriverExtras -lpthread \
				-lueye_api \
				-lgsl -lgslcblas \
				-lrt
				
all-bins		:	$(BINS)

bin/oaxaca-wfc		:	bin/oaxaca-wfc.cpp 		\
				liboaxaca/oaxaca-config.h	\
				liboaxaca/oaxaca.h
	g++ $(BIN_CXXFLAGS) -o bin/oaxaca-wfc bin/oaxaca-wfc.cpp $(BIN_LIBS)
		

bin/oaxaca-wfs		:	bin/oaxaca-wfs.cpp 		\
				liboaxaca/oaxaca-config.h	\
				liboaxaca/oaxaca.h
	g++ $(BIN_CXXFLAGS) -o bin/oaxaca-wfs bin/oaxaca-wfs.cpp $(BIN_LIBS)

install-bins:
	cp $(BINS) /usr/local/bin
	
uninstall-bins:
	for file in $(BIN); do rm -f /usr/local/bin/$$file; done

################################################################################

LIBOAXACA_SRCS		=	liboaxaca/adaptica.cpp		\
				liboaxaca/ids.c			\
				liboaxaca/oaxaca.c		\
				liboaxaca/shm.c			\
				liboaxaca/usleep.c		\
				liboaxaca/wfc.c			\
				liboaxaca/wfits.c		\
				liboaxaca/wfs.c			\
				liboaxaca/wfs-loop.c

LIBOAXACA_HDRS		=	liboaxaca/adaptica.h		\
				liboaxaca/ids.h			\
				liboaxaca/mat.h			\
				liboaxaca/oaxaca.h		\
				liboaxaca/oaxaca-config.h	\
				liboaxaca/wfits.h		\
				liboaxaca/wfs.h		

.PHONY			:	all-liboaxaca
all-liboaxaca		:	liboaxaca/liboaxaca.so

liboaxaca/liboaxaca.so	:	$(LIBOAXACA_SRCS) 		\
				$(LIBOAXACA_HDRS)
	gcc -std=c99 -Os -Wall -fPIC -shared			\
		-o liboaxaca/liboaxaca.so			\
		$(LIBOAXACA_SRCS)		

.PHONY			:	install-liboaxaca
install-liboaxaca	:	all-liboaxaca
	cp liboaxaca/liboaxaca.so /usr/local/lib
	cp liboaxaca/oaxaca.h /usr/local/include
	ldconfig

.PHONY			:	uninstall-liboaxaca	
uninstall-liboaxaca	:
	rm -f /usr/local/include/oaxaca.h
	rm -f /usr/local/lib/liboaxaca.so
	ldconfig

.PHONY			:	clean-liboaxaca
clean-liboaxaca		:
	rm -f liboaxaca/liboaxaca$(SO)

################################################################################

.PHONY			:	install-chibi-scheme
install-chibi-scheme	:
	which hg >/dev/null || sudo apt-get -y install mercurial
	rm -rf chibi-scheme/
	#curl -Os http://chibi-scheme.googlecode.com/files/chibi-scheme-0.5.3.tgz
	#tar -xzf chibi-scheme-0.5.3.tgz
	#mv chibi-scheme*/ chibi-scheme
	hg clone https://code.google.com/p/chibi-scheme/
	cp repl.scm chibi-scheme/lib/chibi/
	#cp chibi-ffi chibi-scheme/tools/
	cd chibi-scheme; make
	cd chibi-scheme; make test test-libs
	cd chibi-scheme; sudo make install

################################################################################

.PHONY			:	install-adaptica-sdk
install-adaptica-sdk	:
	cd adaptica-sdk; \
	cat Timer.h serverSocketLnx.h ws-util.h >mirrorDriverExtras.h
	cd adaptica-sdk; \
	g++ -Os -fPIC -shared -o libmirrorDriverExtras.so -I. *.cpp
	sudo cp adaptica-sdk/libmirrorDriver.so /usr/lib
	sudo cp adaptica-sdk/libmirrorDriverExtras.so /usr/lib
	sudo cp adaptica-sdk/mirrorDriver.h /usr/include
	sudo cp adaptica-sdk/mirrorDriverExtras.h /usr/include
	sudo ldconfig

################################################################################

.PHONY			:	install-ueye-sdk
install-ueye-sdk	:
	which unzip >/dev/null || sudo apt-get -y install unzip
	mkdir -p ueye-sdk
	cd ueye-sdk; curl -O http://www.ids-imaging.com/frontend/files/Linux_V4.00_32_Bit.zip
	cd ueye-sdk; unzip Linux_V4.00_32_Bit.zip
	cd ueye-sdk; sudo sh ueyesdk-setup-4.0-eth-i686.gz.run

################################################################################

.PHONY			:	install-gsl
install-gsl	:
	sudo apt-get install libgsl0-dev

################################################################################
